package com.lltt.study.controller;

import cn.hutool.core.date.DateUtil;
import cn.hutool.db.handler.StringHandler;
import com.lltt.study.service.ChatAssistant;
import com.lltt.study.service.ChatMemoryAssistant;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class ChatMemoryController {
    @Resource(name = "chat")
    private ChatAssistant chatAssistant;
    @Resource(name = "chatMessageWindowChatMemory")
    private ChatMemoryAssistant chatMessageWindowChatMemory;
    @Resource(name = "chatTokenWindowChatMemory")
    private ChatMemoryAssistant chatTokenWindowChatMemory;

    //没有记忆缓存功能
    @GetMapping(value = "/chatmemory/test1")
    public String chat() {
        String answer01 = chatAssistant.chat("你好，我叫张三");
        System.out.println("answer01 = " + answer01);
        String answer02 = chatAssistant.chat("我的名字是什么");
        System.out.println("answer02 = " + answer02);
        return "success : " + DateUtil.now() + "<br> \n\n answer01: " + answer01 + "<br> \n\n answer02: " + answer02;
    }
    //chatMessageWindowChatMemory实现记忆缓存
    @GetMapping(value = "/chatmemory/test2")
    public String chatMessageWindowChatMemory() {
        chatMessageWindowChatMemory.chatWithMemory(1L, "你好，我的名字叫张三");
        String answer01 = chatMessageWindowChatMemory.chatWithMemory(1L, "我的名字叫什么");
        System.out.println("answer01 = " + answer01);

        chatMessageWindowChatMemory.chatWithMemory(3L, "你好！我的名字是C++");
        String answer02 = chatMessageWindowChatMemory.chatWithMemory(3L, "我的名字是什么");
        System.out.println("answer02返回结果："+answer02);
        return "chatMessageWindowChatMemory success : "
                + DateUtil.now()+"<br> \n\n answer01: "+answer01+"<br> \n\n answer02: "+answer02;
    }
    //
    @GetMapping(value = "/chatmemory/test3")
    public String chatTokenWindowChatMemory(){
        chatTokenWindowChatMemory.chatWithMemory(1L, "你好，我的名字叫mySQL");
        String answer01 = chatTokenWindowChatMemory.chatWithMemory(1L, "我的名字叫什么");
        System.out.println("answer01 = " + answer01);

        chatTokenWindowChatMemory.chatWithMemory(3L, "你好！我的名字是Oracle");
        String answer02 = chatTokenWindowChatMemory.chatWithMemory(3L, "我的名字是什么");
        System.out.println("answer02返回结果："+answer02);
        return "chatMessageWindowChatMemory success : "
                + DateUtil.now()+"<br> \n\n answer01: "+answer01+"<br> \n\n answer02: "+answer02;
    }
}

